<!--订阅弹窗-->
<?php
/**
 * @var \Mslynn\Registerpop\Block\SubscribeBlock $block
 */

if ($block->getEnable()){
    ?>



    <div class="window-cover_con register-now" id="register-now" style="display: none; margin-left: -309px; margin-top: -204px;">
        <img class="register-now_bg" alt="" src="<?php echo $block->getBackgroud() ?>" data-loaded="true">

        <div class="register-now_con">
            <h1 class="register-now_title">
                <?php echo  $block->getTitle();?>
            </h1>
            <?php echo $block->getContent();?>
            <a class="register-now_link" href="javascript:void(0)"  title="Register Now">Register Now</a>
        </div>
        <div class="window-cover_con-close closebtn-alert">
        </div>
    </div>

    <script>
        require(['jquery'], function ($) {
            $(".closebtn-alert").click(function () {
                $("#register-now").hide()
                cache('register', 1,  parseInt('<?php echo $block->getTime2()*60; ?>'))
            })

            $(".register-now_link").click(function () {
                cache('register', 1, parseInt('<?php echo $block->getTime2()*60; ?>'))
                window.location.href='/customer/account/create/'
            })
            console.log('register',cache('register'))
            if (!cache('register')==1){
                setTimeout(function () {
                    $("#register-now").show()
                },parseInt(parseInt('<?php echo $block->getTime1()*1000; ?>')))
            }
        })

        //缓存,默认有效期7天
        function cache(key, value, seconds) {
            var timestamp = Date.parse(new Date()) / 1000
            if (key && value === null) {
                //删除缓存
                localStorage.removeItem(key);
            } else if (key && value) {
                //设置缓存
                if (!seconds) {
                    var expire = timestamp + (3600 * 24 * 1)
                } else {
                    var expire = timestamp + seconds
                }
                value = value + "|" + expire
                localStorage.setItem(key, value);
            } else if (key) {
                //获取缓存
                var val = localStorage.getItem(key);
                if (!val){
                    return  false;
                }
                var tmp = val.split("|")
                if (!tmp[1] || timestamp >= tmp[1]) {
                    localStorage.removeItem(key);
                    return false
                } else {
                    return tmp[0]
                }
            } else {
                alert("key不能空")
            }
        }
    </script>
<?php }?>